from model import Model, Dao
from model.sprint import SprintDao

class Requirement(Model):
    def __init__(self, _dict):
        Model.__init__(self, _dict)

        self.name = _dict['name']
        self.description = _dict['description']
        self.created = _dict['created']
        
        # plan start date and end date
        self.start = _dict['start-date']
        self.end = _dict['end-date']
        
        self.importance = _dict['importance']
        self.state = _dict['state'] # 0: created, 1: selected, 2:implemented, 3:implementing, 4:testing 5:tested
        self.priority = _dict['priority']   # 0 high, 1: medium, 2: low
        self.source = _dict['source']
        self.in_backlog = _dict['in_backlog'] # 0: false, 1: true
        
        # associate fields
        self.sprint_id = _dict['sprint_id']
        self.project_id = _dict['project_id']
        
    def __repr__(self):
        return '<Requirement %r>' % self.name

    def get_sprint(self):
        dao = SprintDao()
        return dao.find_one({'_id':self.sprint_id})
    
class RequirementDao(Dao):
    def __init__(self):
        Dao.__init__(self, Requirement)
        self.collection = 'requirements'